#include "Renderer/shader.h"

#include "Renderer/renderer.h"
#include "Platform/OpenGL/openGLShader.h"

namespace CC
{
    Shader *Shader::Create(const std::string &name, const std::string &vertexFile, const std::string &fragmentFile)
    {
        return new OpenGLShader(name, vertexFile, fragmentFile);
    }

    void ShaderLibrary::Add(const std::string &name, Shader *shader)
    {
        if (!Exists(name))
        {
            m_Shaders[name] = shader;
        }
    }

    void ShaderLibrary::Add(Shader *shader)
    {
        auto &name = shader->GetName();
        Add(name, shader);
    }


    Shader *ShaderLibrary::Load(const std::string &name, const std::string& vertexFile, const std::string& fragmentFile)
    {
        auto shader = Shader::Create(name, vertexFile, fragmentFile);
        Add(name, shader);
        return shader;
    }

    Shader *ShaderLibrary::Get(const std::string &name)
    {
        if(Exists(name))
            return m_Shaders[name];
        return nullptr;
    }

    bool ShaderLibrary::Exists(const std::string &name) const
    {
        return m_Shaders.find(name) != m_Shaders.end();
    }

}